// 写一个名为toCamelCase 方法 实现把 "abc-def-ghi" 转换为 "abcDefGhi"

function toCamelCase(str) {
  str = str.split("-");
  let res = str[0];
  for (let i = 1; i < str.length; i++) {
    let item = str[i];
    item = item[0].toUpperCase() + item.slice(1);
    res += item;
  }
  return res;
}
// 写一个名为toDashJoin 方法 实现把 "abcDefGhi" 转换为 "abc-def-ghi"
function toDashJoin(str) {
  let res = "";
  for (let i of str) {
    if (i >= "A" && i <= "Z") {
      res += "-" + i.toLowerCase();
    } else {
      res += i;
    }
  }
  return res;
}
// 写一个名为toCapitalize 方法 实现首字母大写 如 i like css => I Like Css
function toCapitalize(str) {
  str = str.split(" ");
  let res = "";
  for (let i of str) {
    i = i[0].toUpperCase() + i.slice(1);
    res += i + " ";
  }
  return res;
}
// 写一个名为toBetterUrl 方法 实现把 "CSS value type" 转换为 "css-value-type" ( 只考虑空格和大小写处理)
function toBetterUrl(str) {
  str = str.toLowerCase();
  let res = str.replaceAll(" ", "-");
  //   console.log(str);
  return res;
}

// let str1 = "abc-def-ghi";
// let str2 = "abcDefGhi";
// let str3 = "i like css";
// let str4 = "CSS value type";
// let res1 = toCamelCase(str1);
// let res2 = toDashJoin(str2);
// let res3 = toCapitalize(str3);
// let res4 = toBetterUrl(str4);
// console.log(res1);
// console.log(res2);
// console.log(res3);
// console.log(res4);
// console.log(Math.random().toString());
// console.log(Math.sin(45));
let data = [
  {
    userId: "001",
    userName: "张三(zhangsan)",
  },
  {
    userId: "002",
    userName: "李四(lisi)",
  },
  {
    userId: "003",
    userName: "王二(wanger)",
  },
  {
    userId: "004",
    userName: "麻子(mazi)",
  },
];
data.sort(cmp);
function cmp(obja, objb) {
  const a = obja.userName.split("(")[1][0];
  const b = objb.userName.split("(")[1][0];
  return a > b ? 1 : -1;
}
console.log(data);
